﻿Public Class DateValueModel
    Implements IComparable

    Private _date As Datum
    Private _value As Money

    ''' <summary>
    ''' Specifices date of the entry
    ''' undetermined values are set to 0
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Date_ As Datum
        Get
            Return _date
        End Get
        Set(value As Datum)
            _date = value
        End Set
    End Property

    Public ReadOnly Property DateString As String
        Get
            Dim m As Monat = Date_.Monat
            Return m.ToString + " " + Date_.Jahr.ToString
        End Get
    End Property


    ''' <summary>
    ''' Returns the value connected to the specified date
    ''' </summary>
    ''' <value></value>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Property Value As Money
        Get
            Return _value
        End Get
        Set(value As Money)
            _value = value
        End Set
    End Property

    ''' <summary>
    ''' Returns the percentage of the objects value on the total value. Default stringformat is "0,00 %"
    ''' </summary>
    ''' <returns></returns>
    ''' <remarks></remarks>
    Public Function Percent(totalvalue As Double, Optional stringformat As String = "0,00 %") As String
        If totalvalue > 0 Then
            Dim ouput As Double = (Value.Amount / totalvalue) * 100
            Return ouput.ToString(stringformat)
        End If
        Return ""
    End Function

    Public Overrides Function Equals(obj As Object) As Boolean
        Try
            Dim temp As DateValueModel = obj
            If temp.Date_.Equals(Date_) Then
                Return True
            End If
        Catch ex As Exception
            Return False
        End Try
        Return False
    End Function

    Public Function CompareTo(obj As Object) As Integer Implements System.IComparable.CompareTo
        Try
            Dim temp As DateValueModel = obj
            Return Date_.CompareTo(temp.Date_)
        Catch ex As Exception
            Return 0
        End Try
    End Function
End Class

Public Class DateComparer
    Implements System.Collections.Generic.IEqualityComparer(Of DateValueModel)

    Public Function Equals1(x As DateValueModel, y As DateValueModel) As Boolean Implements System.Collections.Generic.IEqualityComparer(Of DateValueModel).Equals
        If x.Date_.Equals(y.Date_) Then
            Return True
        End If
        Return False
    End Function

    Public Function GetHashCode1(obj As DateValueModel) As Integer Implements System.Collections.Generic.IEqualityComparer(Of DateValueModel).GetHashCode
        Return 0
    End Function
End Class
